import {
	getWeChatOpenIdData,
	saveWeChatUserData
} from "../../api/user";
export default {
	namespaced: true,
	state: {
		uid: uni.getStorageSync('uid') ? uni.getStorageSync('uid') : "", //会员的唯一表示
		token: uni.getStorageSync('token') ? uni.getStorageSync('token') : "", //会员登录验证的token
		openid: uni.getStorageSync('openid') ? uni.getStorageSync('openid') : "", //微信用户登录的唯一标识
		isLogin: uni.getStorageSync('isLogin') ? Boolean(uni.getStorageSync('isLogin')) : false //会员是否登录
	},
	mutations: {
		["LOGIN"](state, payload) {
			state.uid = payload.uid;
			state.token = payload.token;
			state.openid = payload.openid;
			state.isLogin = true;
			uni.setStorageSync('uid', state.uid);
			uni.setStorageSync('token', state.token);
			uni.setStorageSync('openid', state.openid);
			uni.setStorageSync('isLogin', true);
		}
	},
	actions: {
		//获取微信小程序用户的openId
		getWeChatOpenId(conText, payload) {
			return getWeChatOpenIdData(payload).then(res => {
				return res;
			})
		},
		//保存用户信息
		saveWeChatUser(conText, payload) {
			return saveWeChatUserData(payload).then(res => {
				return res;
			})
		}
	}
}